home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 January / january_2001.iso / intercd / root / ^4Developers / VB / visbasdb / VBDB / VBDB Code / VB6 Code / Class 6 / Exercise6AD.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-17  |  14.5 KB  |  495 lines

  1. VERSION 5.00
  2. Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
  3. Begin VB.Form frmPublishers 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Publishers"
  6.    ClientHeight    =   5580
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   4650
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   5580
  14.    ScaleWidth      =   4650
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin MSAdodcLib.Adodc datPublishers 
  17.       Height          =   330
  18.       Left            =   2640
  19.       Top             =   120
  20.       Visible         =   0   'False
  21.       Width           =   1935
  22.       _ExtentX        =   3413
  23.       _ExtentY        =   582
  24.       ConnectMode     =   0
  25.       CursorLocation  =   3
  26.       IsolationLevel  =   -1
  27.       ConnectionTimeout=   15
  28.       CommandTimeout  =   30
  29.       CursorType      =   3
  30.       LockType        =   3
  31.       CommandType     =   1
  32.       CursorOptions   =   0
  33.       CacheSize       =   50
  34.       MaxRecords      =   0
  35.       BOFAction       =   0
  36.       EOFAction       =   0
  37.       ConnectStringType=   1
  38.       Appearance      =   1
  39.       BackColor       =   -2147483643
  40.       ForeColor       =   -2147483640
  41.       Orientation     =   0
  42.       Enabled         =   -1
  43.       Connect         =   "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\VBDB\Working\Biblio.mdb"
  44.       OLEDBString     =   "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\VBDB\Working\Biblio.mdb"
  45.       OLEDBFile       =   ""
  46.       DataSourceName  =   ""
  47.       OtherAttributes =   ""
  48.       UserName        =   ""
  49.       Password        =   ""
  50.       RecordSource    =   "SELECT * FROM Publishers ORDER BY Name"
  51.       Caption         =   "Adodc1"
  52.       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  53.          Name            =   "MS Sans Serif"
  54.          Size            =   8.25
  55.          Charset         =   0
  56.          Weight          =   400
  57.          Underline       =   0   'False
  58.          Italic          =   0   'False
  59.          Strikethrough   =   0   'False
  60.       EndProperty
  61.       _Version        =   393216
  62.    End
  63.    Begin VB.TextBox txtInput 
  64.       DataField       =   "Comments"
  65.       DataSource      =   "datPublishers"
  66.       Height          =   285
  67.       Index           =   9
  68.       Left            =   1320
  69.       Locked          =   -1  'True
  70.       TabIndex        =   9
  71.       Text            =   "Text1"
  72.       Top             =   3360
  73.       Width           =   3255
  74.    End
  75.    Begin VB.TextBox txtInput 
  76.       DataField       =   "Fax"
  77.       DataSource      =   "datPublishers"
  78.       Height          =   285
  79.       Index           =   8
  80.       Left            =   1320
  81.       Locked          =   -1  'True
  82.       TabIndex        =   8
  83.       Text            =   "Text1"
  84.       Top             =   3000
  85.       Width           =   1575
  86.    End
  87.    Begin VB.TextBox txtInput 
  88.       DataField       =   "Telephone"
  89.       DataSource      =   "datPublishers"
  90.       Height          =   285
  91.       Index           =   7
  92.       Left            =   1320
  93.       Locked          =   -1  'True
  94.       TabIndex        =   7
  95.       Text            =   "Text1"
  96.       Top             =   2640
  97.       Width           =   1575
  98.    End
  99.    Begin VB.TextBox txtInput 
  100.       DataField       =   "Zip"
  101.       DataSource      =   "datPublishers"
  102.       Height          =   285
  103.       Index           =   6
  104.       Left            =   1320
  105.       Locked          =   -1  'True
  106.       TabIndex        =   6
  107.       Text            =   "Text1"
  108.       Top             =   2280
  109.       Width           =   1575
  110.    End
  111.    Begin VB.TextBox txtInput 
  112.       DataField       =   "State"
  113.       DataSource      =   "datPublishers"
  114.       Height          =   285
  115.       Index           =   5
  116.       Left            =   1320
  117.       Locked          =   -1  'True
  118.       TabIndex        =   5
  119.       Text            =   "Text1"
  120.       Top             =   1920
  121.       Width           =   1575
  122.    End
  123.    Begin VB.TextBox txtInput 
  124.       DataField       =   "City"
  125.       DataSource      =   "datPublishers"
  126.       Height          =   285
  127.       Index           =   4
  128.       Left            =   1320
  129.       Locked          =   -1  'True
  130.       TabIndex        =   4
  131.       Text            =   "Text1"
  132.       Top             =   1560
  133.       Width           =   3255
  134.    End
  135.    Begin VB.TextBox txtInput 
  136.       DataField       =   "Address"
  137.       DataSource      =   "datPublishers"
  138.       Height          =   285
  139.       Index           =   3
  140.       Left            =   1320
  141.       Locked          =   -1  'True
  142.       TabIndex        =   3
  143.       Text            =   "Text1"
  144.       Top             =   1200
  145.       Width           =   3255
  146.    End
  147.    Begin VB.TextBox txtInput 
  148.       DataField       =   "Company Name"
  149.       DataSource      =   "datPublishers"
  150.       Height          =   285
  151.       Index           =   2
  152.       Left            =   1320
  153.       Locked          =   -1  'True
  154.       TabIndex        =   2
  155.       Text            =   "Text1"
  156.       Top             =   840
  157.       Width           =   3255
  158.    End
  159.    Begin VB.TextBox txtInput 
  160.       DataField       =   "Name"
  161.       DataSource      =   "datPublishers"
  162.       Height          =   285
  163.       Index           =   1
  164.       Left            =   1320
  165.       Locked          =   -1  'True
  166.       TabIndex        =   1
  167.       Text            =   "Text1"
  168.       Top             =   480
  169.       Width           =   3255
  170.    End
  171.    Begin VB.CommandButton cmdHelp 
  172.       Caption         =   "&Help"
  173.       Height          =   375
  174.       Left            =   3240
  175.       TabIndex        =   19
  176.       TabStop         =   0   'False
  177.       Top             =   5160
  178.       Width           =   1215
  179.    End
  180.    Begin VB.CommandButton cmdDone 
  181.       Caption         =   "Do&ne"
  182.       Height          =   375
  183.       Left            =   3240
  184.       TabIndex        =   18
  185.       TabStop         =   0   'False
  186.       Top             =   4680
  187.       Width           =   1215
  188.    End
  189.    Begin VB.CommandButton cmdDelete 
  190.       Caption         =   "&Delete"
  191.       Height          =   375
  192.       Left            =   1680
  193.       TabIndex        =   17
  194.       TabStop         =   0   'False
  195.       Top             =   4680
  196.       Width           =   1215
  197.    End
  198.    Begin VB.CommandButton cmdEdit 
  199.       Caption         =   "&Edit"
  200.       Height          =   375
  201.       Left            =   120
  202.       TabIndex        =   16
  203.       TabStop         =   0   'False
  204.       Top             =   4200
  205.       Width           =   1215
  206.    End
  207.    Begin VB.CommandButton cmdCancel 
  208.       Caption         =   "&Cancel"
  209.       Height          =   375
  210.       Left            =   3240
  211.       TabIndex        =   15
  212.       TabStop         =   0   'False
  213.       Top             =   4200
  214.       Width           =   1215
  215.    End
  216.    Begin VB.CommandButton cmdSave 
  217.       Caption         =   "&Save"
  218.       Height          =   375
  219.       Left            =   1680
  220.       TabIndex        =   14
  221.       TabStop         =   0   'False
  222.       Top             =   4200
  223.       Width           =   1215
  224.    End
  225.    Begin VB.CommandButton cmdAddNew 
  226.       Caption         =   "&Add New"
  227.       Height          =   375
  228.       Left            =   120
  229.       TabIndex        =   13
  230.       TabStop         =   0   'False
  231.       Top             =   4680
  232.       Width           =   1215
  233.    End
  234.    Begin VB.CommandButton cmdNext 
  235.       Caption         =   "Next =>"
  236.       Height          =   255
  237.       Left            =   2520
  238.       TabIndex        =   12
  239.       TabStop         =   0   'False
  240.       Top             =   3840
  241.       Width           =   1215
  242.    End
  243.    Begin VB.CommandButton cmdPrevious 
  244.       Caption         =   "<= Previous"
  245.       Height          =   255
  246.       Left            =   1080
  247.       TabIndex        =   11
  248.       TabStop         =   0   'False
  249.       Top             =   3840
  250.       Width           =   1215
  251.    End
  252.    Begin VB.TextBox txtInput 
  253.       DataField       =   "PubID"
  254.       DataSource      =   "datPublishers"
  255.       Height          =   285
  256.       Index           =   0
  257.       Left            =   1320
  258.       Locked          =   -1  'True
  259.       TabIndex        =   10
  260.       TabStop         =   0   'False
  261.       Text            =   "Text1"
  262.       Top             =   120
  263.       Width           =   1215
  264.    End
  265.    Begin VB.Label Label1 
  266.       Caption         =   "Comments"
  267.       Height          =   255
  268.       Index           =   9
  269.       Left            =   120
  270.       TabIndex        =   28
  271.       Top             =   3360
  272.       Width           =   1215
  273.    End
  274.    Begin VB.Label Label1 
  275.       Caption         =   "FAX"
  276.       Height          =   255
  277.       Index           =   8
  278.       Left            =   120
  279.       TabIndex        =   27
  280.       Top             =   3000
  281.       Width           =   1215
  282.    End
  283.    Begin VB.Label Label1 
  284.       Caption         =   "Telephone"
  285.       Height          =   255
  286.       Index           =   7
  287.       Left            =   120
  288.       TabIndex        =   26
  289.       Top             =   2640
  290.       Width           =   1215
  291.    End
  292.    Begin VB.Label Label1 
  293.       Caption         =   "Zip"
  294.       Height          =   255
  295.       Index           =   6
  296.       Left            =   120
  297.       TabIndex        =   25
  298.       Top             =   2280
  299.       Width           =   1215
  300.    End
  301.    Begin VB.Label Label1 
  302.       Caption         =   "State"
  303.       Height          =   255
  304.       Index           =   5
  305.       Left            =   120
  306.       TabIndex        =   24
  307.       Top             =   1920
  308.       Width           =   1215
  309.    End
  310.    Begin VB.Label Label1 
  311.       Caption         =   "City"
  312.       Height          =   255
  313.       Index           =   4
  314.       Left            =   120
  315.       TabIndex        =   23
  316.       Top             =   1560
  317.       Width           =   1215
  318.    End
  319.    Begin VB.Label Label1 
  320.       Caption         =   "Address"
  321.       Height          =   255
  322.       Index           =   3
  323.       Left            =   120
  324.       TabIndex        =   22
  325.       Top             =   1200
  326.       Width           =   1215
  327.    End
  328.    Begin VB.Label Label1 
  329.       Caption         =   "Company Name"
  330.       Height          =   255
  331.       Index           =   2
  332.       Left            =   120
  333.       TabIndex        =   21
  334.       Top             =   840
  335.       Width           =   1215
  336.    End
  337.    Begin VB.Label Label1 
  338.       Caption         =   "Name"
  339.       Height          =   255
  340.       Index           =   1
  341.       Left            =   120
  342.       TabIndex        =   20
  343.       Top             =   480
  344.       Width           =   1215
  345.    End
  346.    Begin VB.Label Label1 
  347.       Caption         =   "Publisher ID"
  348.       Height          =   255
  349.       Index           =   0
  350.       Left            =   120
  351.       TabIndex        =   0
  352.       Top             =   120
  353.       Width           =   1215
  354.    End
  355. Attribute VB_Name = "frmPublishers"
  356. Attribute VB_GlobalNameSpace = False
  357. Attribute VB_Creatable = False
  358. Attribute VB_PredeclaredId = True
  359. Attribute VB_Exposed = False
  360. Option Explicit
  361. Private Declare Function WinHelp Lib "user32" Alias "WinHelpA" (ByVal hwnd As Long, ByVal lpHelpFile As String, ByVal wCommand As Long, ByVal dwData As Long) As Long
  362. Private Const HELP_FINDER = &HB&
  363. Private Sub ValidateData(AllOK As Boolean)
  364. Dim Message As String
  365. AllOK = True
  366. 'Check for name
  367. If Len(txtInput(1).Text) = 0 Then
  368.   Message = "You must enter a Publisher Name." & vbCrLf & Message
  369.   txtInput(1).SetFocus
  370.   AllOK = False
  371. End If
  372. If Not (AllOK) Then
  373.   MsgBox Message, vbOKOnly + vbInformation, "Validation Error"
  374. End If
  375. End Sub
  376. Private Sub cmdAddNew_Click()
  377. On Error GoTo HandleErrors
  378. Call SetState("Add")
  379. Exit Sub
  380. HandleErrors:
  381. Select Case MsgBox(Err.Description, vbCritical + vbAbortRetryIgnore, "Error Number" + Str(Err.Number) + " in " + Err.Source)
  382. Case vbAbort
  383.   Exit Sub
  384. Case vbRetry
  385.   Resume
  386. Case vbIgnore
  387.   Resume Next
  388. End Select
  389. End Sub
  390. Private Sub cmdCancel_Click()
  391. Call SetState("View")
  392. End Sub
  393. Private Sub cmdDelete_Click()
  394. Dim Response As Integer
  395. On Error GoTo HandleErrors
  396. Response = MsgBox("Are you sure you want to delete this record?", vbYesNo + vbQuestion + vbDefaultButton2, "Delete")
  397. If Response = vbNo Then
  398.   Exit Sub
  399. End If
  400. Exit Sub
  401. HandleErrors:
  402. Select Case MsgBox(Err.Description, vbCritical + vbAbortRetryIgnore, "Error Number" + Str(Err.Number) + " in " + Err.Source)
  403. Case vbAbort
  404.   Exit Sub
  405. Case vbRetry
  406.   Resume
  407. Case vbIgnore
  408.   Resume Next
  409. End Select
  410. End Sub
  411. Private Sub cmdEdit_Click()
  412. Call SetState("Edit")
  413. End Sub
  414. Private Sub cmdHelp_Click()
  415. Dim Rtn As Long
  416. Rtn = WinHelp(frmPublishers.hwnd, App.HelpFile, HELP_FINDER, CLng(0))
  417. End Sub
  418. Private Sub cmdNext_Click()
  419. datPublishers.Recordset.MoveNext
  420. If datPublishers.Recordset.EOF Then
  421.   Beep
  422.   datPublishers.Recordset.MoveLast
  423. End If
  424. End Sub
  425. Private Sub cmdPrevious_Click()
  426. datPublishers.Recordset.MovePrevious
  427. If datPublishers.Recordset.BOF Then
  428.   Beep
  429.   datPublishers.Recordset.MoveFirst
  430. End If
  431. End Sub
  432. Private Sub cmdSave_Click()
  433. Dim Valid As Boolean
  434. Call ValidateData(Valid)
  435. If Not (Valid) Then Exit Sub
  436. On Error GoTo HandleErrors
  437. MsgBox "Record saved.", vbOKOnly + vbInformation, "Save"
  438. Call SetState("View")
  439. Exit Sub
  440. HandleErrors:
  441. Select Case MsgBox(Err.Description, vbCritical + vbAbortRetryIgnore, "Error Number" + Str(Err.Number) + " in " + Err.Source)
  442. Case vbAbort
  443.   Exit Sub
  444. Case vbRetry
  445.   Resume
  446. Case vbIgnore
  447.   Resume Next
  448. End Select
  449. End Sub
  450. Private Sub SetState(AppState As String)
  451. Dim I As Integer
  452. Select Case AppState
  453. Case "View"
  454.   txtInput(0).BackColor = vbWhite
  455.   For I = 1 To 9
  456.     txtInput(I).Locked = True
  457.   Next I
  458.   cmdPrevious.Enabled = True
  459.   cmdNext.Enabled = True
  460.   cmdAddNew.Enabled = True
  461.   cmdSave.Enabled = False
  462.   cmdCancel.Enabled = False
  463.   cmdEdit.Enabled = True
  464.   cmdDelete.Enabled = True
  465.   cmdDone.Enabled = True
  466.   txtInput(1).SetFocus
  467. Case "Add", "Edit"
  468.   txtInput(0).BackColor = vbRed
  469.   For I = 1 To 9
  470.     txtInput(I).Locked = False
  471.   Next I
  472.   cmdPrevious.Enabled = False
  473.   cmdNext.Enabled = False
  474.   cmdAddNew.Enabled = False
  475.   cmdSave.Enabled = True
  476.   cmdCancel.Enabled = True
  477.   cmdEdit.Enabled = False
  478.   cmdDelete.Enabled = False
  479.   cmdDone.Enabled = False
  480.   txtInput(1).SetFocus
  481. End Select
  482. End Sub
  483. Private Sub Form_Activate()
  484. Call SetState("View")
  485. End Sub
  486. Private Sub txtInput_KeyPress(Index As Integer, KeyAscii As Integer)
  487. If KeyAscii = vbKeyReturn Then
  488.   If Index <> 9 Then
  489.     txtInput(Index + 1).SetFocus
  490.   Else
  491.     txtInput(1).SetFocus
  492.   End If
  493. End If
  494. End Sub
  495.